using UnityEngine;

public class VialController : MonoBehaviour {

    [SerializeField]
    string _form = "";

    float startAngle;
    float time;

    void Awake() {
        startAngle = transform.eulerAngles.z;
    }

    void Update() {
        time += Time.deltaTime;
        time %= 2;

        float currentAngle = ((Mathf.PingPong(time, 1) * 2) - 1) * 10;

        transform.rotation = Quaternion.Euler(0, 0, startAngle + currentAngle);
    }

    void OnTriggerEnter2D(Collider2D collider) {
        if(collider.CompareTag("Player"))
            Invoke(collider.attachedRigidbody.GetComponent<FormController>());
    }

    void Invoke(FormController form) {
        form.EnableForm(_form);
        gameObject.SetActive(false);
    }
}